package com.example.travelexpensemanager;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Show_details_listviewadapter extends BaseAdapter {

	Activity activity;
	public ArrayList<HashMap<Integer, String>> arrHashMap;

	public Show_details_listviewadapter(Activity activity,
			ArrayList<HashMap<Integer, String>> arrHashMap) {
		super();
		this.activity = activity;
		this.arrHashMap = arrHashMap;
	}

	private class AllTextViews {
		TextView textview1, textview2;
	}

	@Override
	public int getCount() {
		return arrHashMap.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		AllTextViews allTextViews;
		/* Creating an inflater */
		LayoutInflater layoutInflater = activity.getLayoutInflater();

		if (convertView == null) {
			/*
			 * Create an object so that it can the references of all the
			 * controls
			 */
			allTextViews = new AllTextViews();
			/*
			 * Assigning the view of all the textviews which you want into every
			 * listview
			 */
			convertView = layoutInflater.inflate(R.layout.list_row, null);
			/* Assigning the ids to store references */
			allTextViews.textview1 = (TextView) convertView
					.findViewById(R.id.memberTableMember);
			allTextViews.textview2 = (TextView) convertView
					.findViewById(R.id.Paid);
			/* Assigning the object to the view */
			convertView.setTag(allTextViews);
		} else {
			/*
			 * Get view is called every time setAdapter is calling itself to add
			 * a view
			 */
			allTextViews = (AllTextViews) convertView.getTag();
		}
		/*
		 * Arraylists of hashmaps come and then every time a new hashmap is
		 * assigned
		 */
		HashMap<Integer, String> tempHashMap = arrHashMap.get(position);
		allTextViews.textview1.setText(tempHashMap.get(0));
		allTextViews.textview2.setText(tempHashMap.get(1));

		return convertView;
	}

}
